package com.hex.ds.hdtp.core.app.data.contrast.converter;

import com.hex.ds.hdtp.core.app.data.contrast.dto.ContrastResultExcelDto;
import com.hex.ds.hdtp.core.app.data.contrast.dto.request.CrossDbContrastListRequestDto;
import com.hex.ds.hdtp.core.app.data.contrast.dto.response.CrossDbContrastListResponseDto;
import com.hex.ds.hdtp.core.inf.data.contrast.po.CrossDbContrastListPo;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.Arrays;
import java.util.List;

/**
 * @Package: com.hex.ds.hdtp.core.app.data.contrast.converter
 * @ClassName ICrossDbContrastListConverter
 * @Description: 跨库比对清单-DTO对象转PO对象转换器
 * @Author: wz.li
 * @Date 2023/7/25 19:41
 * @Version v2.0.2
 **/
@Mapper(componentModel = "spring")
public interface ICrossDbContrastListConverter {

    /*
     * @Method: toCrossDbContrastListPo <br>
     * @Param: [crossDbContrastListRequestDto] <br>
     * @Return: com.hex.ds.hdtp.core.inf.data.contrast.po.CrossDbContrastListPo <br>
     * @Description：RequestDto对象转Po对象<br>
     * @Author： wz.li<br>
     * @Date： 2023/7/25 19:43 <br>
     * @Version： V2.0.2<br>
     */
    @Mapping(target = "excludeField", expression = "java(MapStruct.listToStr(crossDbContrastListRequestDto.getExcludeField()))")
    @Mapping(target = "removeRepeatCountField", expression = "java(MapStruct.listToStr(crossDbContrastListRequestDto.getRemoveRepeatCountField()))")
    @Mapping(target = "groupCountField", expression = "java(MapStruct.listToStr(crossDbContrastListRequestDto.getGroupCountField()))")
    @Mapping(target = "countField", expression = "java(MapStruct.listToStr(crossDbContrastListRequestDto.getCountField()))")
    @Mapping(target = "sumField", expression = "java(MapStruct.listToStr(crossDbContrastListRequestDto.getSumField()))")
    @Mapping(target = "trimField", expression = "java(MapStruct.listToStr(crossDbContrastListRequestDto.getTrimField()))")
    @Mapping(target = "emptyField", expression = "java(MapStruct.listToStr(crossDbContrastListRequestDto.getEmptyField()))")
    CrossDbContrastListPo toCrossDbContrastListPo(CrossDbContrastListRequestDto crossDbContrastListRequestDto);


    @Mapping(target = "excludeField", expression = "java(MapStruct.strToList(crossDbContrastListPo.getExcludeField()))")
    @Mapping(target = "removeRepeatCountField", expression = "java(MapStruct.strToList(crossDbContrastListPo.getRemoveRepeatCountField()))")
    @Mapping(target = "groupCountField", expression = "java(MapStruct.strToList(crossDbContrastListPo.getGroupCountField()))")
    @Mapping(target = "countField", expression = "java(MapStruct.strToList(crossDbContrastListPo.getCountField()))")
    @Mapping(target = "sumField", expression = "java(MapStruct.strToList(crossDbContrastListPo.getSumField()))")
    @Mapping(target = "trimField", expression = "java(MapStruct.strToList(crossDbContrastListPo.getTrimField()))")
    @Mapping(target = "emptyField", expression = "java(MapStruct.strToList(crossDbContrastListPo.getEmptyField()))")
    CrossDbContrastListResponseDto toCrossDbContrastListResponseDto(CrossDbContrastListPo crossDbContrastListPo);

    /*
     * @Method: toCrossDbContrastListResponseDtoList <br>
     * @Param: [crossDbContrastListPos] <br>
     * @Return: java.util.List<com.hex.ds.hdtp.core.app.data.contrast.dto.response.CrossDbContrastListResponseDto> <br>
     * @Description：PO对象集合转换ResponseDto对象集合<br>
     * @Author： wz.li<br>
     * @Date： 2023/7/25 19:44 <br>
     * @Version： V2.0.2<br>
     */
    List<CrossDbContrastListResponseDto> toCrossDbContrastListResponseDtoList(List<CrossDbContrastListPo> crossDbContrastListPos);

    /*
     * @Method toCrossDbContrastListRequestDto
     * @Param
     * @Param crossDbContrastListResponseDto
     * @Return com.hex.ds.hdtp.core.app.data.contrast.dto.request.CrossDbContrastListRequestDto
     * @Description Response 转 Request
     * @Author xin.zhao
     * @Date 2023/10/10 15:42
     * @Version V1.0
     */
    CrossDbContrastListRequestDto toCrossDbContrastListRequestDto(CrossDbContrastListResponseDto crossDbContrastListResponseDto);

    @Mapping(target = "isCreateTable", source = "crossDbContrastListResponseDto.contrastListResult.isCreateTable")
    @Mapping(target = "isFieldCount", source = "crossDbContrastListResponseDto.contrastListResult.isFieldCount")
    @Mapping(target = "isHasData", source = "crossDbContrastListResponseDto.contrastListResult.isHasData")
    @Mapping(target = "isStatisticsDataCount", source = "crossDbContrastListResponseDto.contrastListResult.isStatisticsDataCount")
    @Mapping(target = "isAllField", source = "crossDbContrastListResponseDto.contrastListResult.isAllField")
    @Mapping(target = "isFieldName", source = "crossDbContrastListResponseDto.contrastListResult.isFieldName")
    @Mapping(target = "isContrastPartitionField", source = "crossDbContrastListResponseDto.contrastListResult.isContrastPartitionField")
    @Mapping(target = "isContrastFieldLength", source = "crossDbContrastListResponseDto.contrastListResult.isContrastFieldLength")
    @Mapping(target = "isContrastFieldPrecision", source = "crossDbContrastListResponseDto.contrastListResult.isContrastFieldPrecision")
    @Mapping(target = "encodingFormat", source = "crossDbContrastListResponseDto.contrastListResultMessage.EncodingFormat")
    @Mapping(target = "isSumCharLength", source = "crossDbContrastListResponseDto.contrastListResult.isSumCharLength")
    @Mapping(target = "isSumCharTrimLength", source = "crossDbContrastListResponseDto.contrastListResult.isSumCharTrimLength")
    @Mapping(target = "isMaxCharLength", source = "crossDbContrastListResponseDto.contrastListResult.isMaxCharLength")
    @Mapping(target = "isStatisticsNumberSum", source = "crossDbContrastListResponseDto.contrastListResult.isStatisticsNumberSum")
    @Mapping(target = "removeRepeatCountField", source = "crossDbContrastListResponseDto.contrastListResult.removeRepeatCountField")
    @Mapping(target = "isContrastFieldType", source = "crossDbContrastListResponseDto.contrastListResult.isContrastFieldType")
    @Mapping(target = "groupCountField", source = "crossDbContrastListResponseDto.contrastListResult.groupCountField")
    @Mapping(target = "countField", source = "crossDbContrastListResponseDto.contrastListResult.countField")
    @Mapping(target = "sumField", source = "crossDbContrastListResponseDto.contrastListResult.sumField")
    @Mapping(target = "trimField", source = "crossDbContrastListResponseDto.contrastListResult.trimField")
    @Mapping(target = "isCharNullToEmpty", source = "crossDbContrastListResponseDto.contrastListResult.isCharNullToEmpty")
    @Mapping(target = "isNumberNullToZero", source = "crossDbContrastListResponseDto.contrastListResult.isNumberNullToZero")
    @Mapping(target = "isCreateTableMsg", source = "crossDbContrastListResponseDto.contrastListResultMessage.isCreateTable")
    @Mapping(target = "isFieldCountMsg", source = "crossDbContrastListResponseDto.contrastListResultMessage.isFieldCount")
    @Mapping(target = "isHasDataMsg", source = "crossDbContrastListResponseDto.contrastListResultMessage.isHasData")
    @Mapping(target = "isStatisticsDataCountMsg", source = "crossDbContrastListResponseDto.contrastListResultMessage.isStatisticsDataCount")
    @Mapping(target = "isAllFieldMsg", source = "crossDbContrastListResponseDto.contrastListResultMessage.isAllField")
    ContrastResultExcelDto toContrastExcelDto(CrossDbContrastListResponseDto crossDbContrastListResponseDto, int index);


    class MapStruct {
        public static List<String> strToList(String str) {
            if (StringUtils.isNotEmpty(str)) {
                return Arrays.asList(str.split(","));
            }
            return null;
        }

        public static String listToStr(List<String> list) {
            return StringUtils.join(list, ",");
        }
    }
}
